import { path, successCode, tokenVarName } from "@/config"

export default {
	methods: {
		toChooseImage() {},
		toUploadFile(options = {}) {
			return new Promise((resolve, reject) => {
				uni.uploadFile({
					url: path + "/system/oss/upload",
					name: "upfile",
					header: {
						[tokenVarName]: uni.getStorageSync("token") || "",
					},
					...options,
					success: ({ data }) => {
						data = JSON.parse(data)
						if (data.code == successCode) {
							resolve(data.data)
						} else {
							reject("上传失败")
						}
					},
					fail: reject,
				})
			})
		},
	},
}
